﻿namespace ScrumLite.Data
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using ScrumLite.Data;

    public class MeasureStore: IMeasureStore
    {
        public Measure[] GetMeasures(string processName)
        {
            using (ScrumLiteDataContext context = new ScrumLiteDataContext())
            {
                IQueryable<Measure> query = (from p in context.Processes
                                                   from m in context.Measures
                                                   where p.name == processName &&
                                                   m.fk_process == p.id
                                                   select m);
                return query.ToArray();
            }
        }

        public ProjectMeasure[] GetProjectMeasures(Guid projectUri, string processName)
        {
            using (ScrumLiteDataContext context = new ScrumLiteDataContext())
            {
                IQueryable<ProjectMeasure> query = (from pm in context.ProjectMeasures
                                                   from p in context.Processes
                                                   from m in context.Measures
                                                   where p.name == processName &&
                                                   m.fk_process == p.id &&
                                                   pm.fk_project == projectUri &&
                                                   pm.fk_measure == m.id
                                                   select pm);
                return query.ToArray();
            }
        }
       
    }
}
